package com.icangya.Utils;

import java.io.FileInputStream;
import java.io.InputStream;

public class FileType{
    public static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder();
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }

    /**
     *
     * @param b
     * @throws Exception
     */
    public static String getSuffix(byte[] b) throws Exception {
//        FileInputStream is = new FileInputStream("F:\\相册\\微信图片\\03.jpg");
//        byte[] b = new byte[3];
//        is.read(b, 0, b.length);
        String xxx = bytesToHexString(b);
        xxx = xxx.toUpperCase();
        System.out.println("头文件是：" + xxx.substring(6));
        String ooo = TypeDict.checkType(xxx.substring(6));
        System.out.println("后缀名是：" + ooo);

        return ooo;
    }
    

}